#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @FileName  :json_file_from_excel.py
# @Time      :2024/10/19 19:34
# @Author    :zhou_yi


import pandas as pd


class MongoData:
    def __init__(self, file_name):
        self.__filename = file_name

    @property
    def filename(self):
        return self.__filename

    def json_address(self):
        _df = pd.read_excel(self.filename, sheet_name='有害垃圾点位', header=1)

        _df['tel'] = _df['tel'].astype(str)
        _df = _df[
            ['_id', 'point', 'long', 'lat', 'name', 'customID', 'custom', 'part', 'manager', 'tel', 'notice', 'address',
             'code']]

        _df['notice'] = _df['notice'].fillna('')
        _df.to_json('../db/有害垃圾点位.json', orient='records', force_ascii=False)

    def json_company(self):
        _df = pd.read_excel(self.filename, sheet_name='相关方信息', header=1)
        # ['编号','名称', '法人', '地址','纳税人识别号', '开户行', '账户', '财务电话', '相关项目', '联系人', '联系电话']
        # ['_id','name', 'jur_person', 'address', 'tax','bank', 'account', 'tel_1', 'relation','user', 'tel_2']
        # print(_df)
        _df.fillna('', inplace=True)

        _df['tel_1'] = _df['tel_1'].astype(str)
        _df['tel_2'] = _df['tel_2'].astype(str)
        _df['account'] = _df['account'].astype(str)

        _df.to_json('../db/相关方信息.json', orient='records', force_ascii=False)


if __name__ == '__main__':
    m = MongoData('../db/company.xlsx')
    # m.json_three()
    m.json_company()
    m.json_address()
    print('完成！！！')
    ...
